package com.cyf.db.mapper.smartCity;

import com.cyf.db.bean.LocalCarWarning;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author hfy
 * @date 2018/12/10
 */
public interface LocalCarWarningMapper {

    @Insert("insert into local_carwarning(license, createdUserId, createdTime, `status`, parkingId) " +
            "values(#{c.license}, #{c.createdUserId}, #{c.createdTime}, 1, #{c.parkingId})")
    @SelectKey(statement = "select LAST_INSERT_ID()", keyProperty = "c.id", before = false, resultType = int.class)
    void insert(@Param("c") LocalCarWarning carWarning);

    @Select("<script>" +
            "select * from local_carwarning " +
            "where status = 1 and parkingId = #{parkingId} " +
            "<if test=\" license != null and license != '' \">" +
            "   and license like '${license}%' " +
            "</if>" +
            "order by createdTime desc " +
            "</script>")
    List<LocalCarWarning> listByPlateAndParkingId(@Param("license") String license,
                                                  @Param("parkingId") Integer parkingId);
    @Select("select count(id) from local_carwarning " +
            "where status = 1 and license = #{license} and parkingId = #{parkingId}")
    Integer countByLicenseAndParkingId(@Param("license") String license,
                                       @Param("parkingId") Integer parkingId);

    @Select("select * from local_carwarning where id = #{id}")
    LocalCarWarning getById(@Param("id") Integer id);

    @Update("update local_carwarning set license = #{license} where id = #{id}")
    void update(@Param("id") Integer id, @Param("license") String license);

    @Update("update local_carwarning set status = 0 where id = #{id}")
    void logicDeleteById(@Param("id") Integer id);
}
